package com.diy.sigmund.diyuser.test.controller;

import com.alibaba.excel.EasyExcel;
import com.diy.sigmund.diycommon.entity.ResultMsg;
import com.diy.sigmund.diycommon.spring.anno.IgnoreTokenVerification;
import java.io.IOException;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author ylm-sigmund
 * @since 2021/8/17 12:04
 */
@RestController
@RequestMapping("/user")
public class ReceiveFileController {

    private static final Logger log = LoggerFactory.getLogger(ReceiveFileController.class);

    @IgnoreTokenVerification
    @PostMapping(value = "/receiveFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    ResultMsg receiveFile(@RequestPart("file") MultipartFile file,
            @RequestPart("file1") MultipartFile file1,
            @RequestParam String name,
            @RequestParam String phone) throws IOException {
        log.info("name:{},phone:{}", name, phone);
        log.info("getOriginalFilename:{}", file.getOriginalFilename());
        List<Object> objects = EasyExcel.read(file.getInputStream()).sheet().doReadSync();
        return ResultMsg.success(objects);
    }
}
